import { createRouter, createWebHistory } from 'vue-router'
import VueCookies from 'vue-cookies'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/site',
      name: '主页',
      component: () => import('../views/Home.vue'),
      children: [{
        path: "/site/project",
        name: "项目页",
        component: () => import('../views/activity/Activity.vue'),
      }, {
        path: "/site/projectInfo",
        name: "项目详情",
        component: () => import('../views/activity/ActivityInfo.vue'),
      },
      ]
    },
    {
      path: '/login',
      name: '登录',
      component: () => import('../views/Login.vue')
    }, {
      path: "/",
      name: "layout",
      component: () => import('../views/Layout.vue'),
      children: [{
        path: "/home",
        name: "首页",
        component: () => import('../views/home/Home.vue'),
      },
      {
        path: "/setting/myinfo",
        name: "我的消息",
        component: () => import('../views/setting/MyInfo.vue'),
      }, {
        path: "/activity/activityList",
        name: "活动列表",
        component: () => import('../views/activity/activityList.vue'),
      }, {
        path: "/apply/applyList",
        name: "申请列表",
        component: () => import('../views/apply/ApplyList.vue'),
      }, {
        path: "/rating/ratinglist",
        name: "评论",
        component: () => import('../views/rating/RatingInfoList.vue'),
      }, {
        path: "/setting/user",
        name: "系统用户管理",
        component: () => import('../views/setting/UserList.vue'),
      }, {
        path: "/user/applyInfo",
        name: "申请记录",
        component: () => import('../views/setting/ApplyList.vue'),
      }, {
        path: "/user/recordInfo",
        name: "志愿记录",
        component: () => import('../views/setting/RecordInfoList.vue'),
      }]
    }
  ]
})

router.beforeEach((to, from, next) => {
  const userInfo = VueCookies.get("userInfo");
  if (!userInfo && to.path != "/login" && to.path != "/site/project" && to.path != "/site/projectInfo") {
    router.push("/login");
  }
  next();
})

export default router
